using LuckyLang.AST.Expression.ValueTyre;

namespace LuckyLang.AST.Statement;

public class WhileStatement : Statement
{
    public Expression.Expression     Expr  { get; set; }
    public BlockStatement Block { get; set; }

    public WhileStatement(Expression.Expression expr,BlockStatement block)
    {
        Block = block;
        Expr  = expr;
    }
    public override void Run(ref VariateManager Manager)
    {
        Manager.Add();
        while (true)
        {
            var a = Expr.GetValue(ref Manager);
            if (a is BoolValue)
            {
                if ((bool)a.TheValue)
                {
                    Block.Run(ref Manager);
                }else break;
            }else break;
        }
        Manager.Remove();
    }
}